home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / utmisc2 / fiflb382.lha / fifo.doc < prev    next >
Text File  |  1996-04-11  |  12KB  |  312 lines

  1.  
  2.                 FIFO.DOC
  3.  
  4.          Placed in the public domain by Matthew Dillon
  5.  
  6.         Last maintainer:
  7.  
  8.              Jörg Höhle (Joerg.Hoehle@gmd.de)
  9.  
  10.         Version 38.2
  11.  
  12.  
  13.     (1) INSTALLATION
  14.  
  15.     To Install the system you must install both FIFO-HANDLER and
  16.     FIFO.LIBRARY.
  17.  
  18.     1> lharc -r -x -a x fifolib38_1.lha
  19.     1> Copy l/fifo-handler l:
  20.     1> Copy libs/fifo.library libs:
  21.     1> Copy bin/RemCLI C:        (or anywhere in your path)
  22.  
  23.     THERE IS NO MOUNTLIST OR MOUNT FOR FIFO: ... To start the handler
  24.     and make FIFO: available to programs, you must RUN it from your
  25.     startup-sequence.  Generally the easiest way to do this is to
  26.     include the following line:
  27.  
  28.     run <nil: >nil: l:fifo-handler
  29.  
  30.     IF YOU HAVE A FIFO: ENTRY IN YOUR MOUNTLIST, PLEASE DELETE IT TO
  31.     PREVENT ACCIDENTLY TRYING TO MOUNT IT.
  32.  
  33.     (2) SIMPLE EXAMPLE TO GET YOU STARTED
  34.  
  35.     This is a simple example to get you started.  Please refer to
  36.     section (3) below for a description of the options.
  37.  
  38.     1> Type fifo:pipe/r
  39.     1> run Type s:startup-sequence >fifo:pipe/wmKe
  40.  
  41.     This particular examples requires that the reader be started first
  42.     (due to the 'K' flag in the writer) but also allows you to ^C the
  43.     reader (the first Type command) without locking up the writer.
  44.  
  45.     (3) USAGE FOR FIFO:
  46.  
  47.     FIFO: is like PIPE: but is based on fifo.library rather than its
  48.     own implementation.  Full master/slave support exists.    Since FIFO:
  49.     uses fifo.library, programs that require non-blocking IO capability
  50.     can access one side of a FIFO: connection via the fifo.library
  51.     instead of FIFO:
  52.  
  53.     The implementation of FIFO: and fifo.library is a billion times
  54.     better than that for my original PIPE: handler.
  55.  
  56.     The primary difference with FIFO: is that it is based on a
  57.     MASTER-SLAVE connection.  Two MASTER-SLAVE connections going in
  58.     opposite directions yields a full-duplex connection.  When using
  59.     FIFO: to direct one program's output to another's input you must
  60.     explicitly specify one of the FIFO:'s to be the master and the
  61.     other the slave, as well as specify read & write flags.  The
  62.     general format for accessing the FIFO: handler is as follows:
  63.  
  64.         FIFO:<name>/<flags>
  65.  
  66.     <name>:    a valid fifo name
  67.  
  68.     name may be any combination of alpha numerics up to 125 chars long,
  69.     and is case sensitive.    FIFO: will append either "_m" or "_s" to
  70.     the name it supplies to fifo.library depending on whether master
  71.     mode or slave mode is selected.
  72.  
  73.     <flags>:    a valid combination of flags
  74.  
  75.     r   open for read.  Allows you to read from this fifo.
  76.  
  77.     w   open for write.  Allows you to write to this fifo.
  78.  
  79.     rw  open for read & write (full duplex).  This opens a
  80.         full duplex connection, generally useful only in
  81.         remote-shell applications.
  82.  
  83.     c   open in cooked mode - must be specified on one side only,
  84.         usually the slave side.  Any data received by the slave
  85.         side is cooked before continuing on to the slave.  When used
  86.         with the 's' flag, this allows the slave side, usually a
  87.         shell and/or program, to change between cooked and raw mode
  88.         with the standard SetMode() call.
  89.  
  90.     e   EOF mode (when combined with 'w').  When this file handle
  91.         is closed, an EOF will be sent to the other side.
  92.  
  93.         If not specified, you can cause several programs to 'append'
  94.         their output onto a single FIFO all of which is read by a
  95.         single program.  This can be useful in log-recorder
  96.         applications, for example.
  97.  
  98.         Specifying the 'e' flag generates an EOF after the last byte
  99.         of data is written to the FIFO and the writer closes it.  A
  100.         reader will read the data and then receive the EOF, generally
  101.         terminating reader operations.
  102.  
  103.     k   KEEP mode.    If a writer opens a fifo, writes data, then
  104.         closes the fifo before a reader has a chance to open the
  105.         fifo, this flag prevents the data from being lost.
  106.  
  107.         If not specified, the data will be lost.  Generally you
  108.         want to specify this flag.
  109.  
  110.     K   READER REQUIRED mode.  When specified, any Write() operation
  111.         to a fifo for which there is no reader will FAIL.  This will
  112.         prevent lockups from occurring when you use FIFO: to pipe
  113.         several processes together and then ^C the last one.
  114.  
  115.         ** This can be an important option to use to prevent hung
  116.            processes!!! **
  117.  
  118.     m   select master side (else slave).  For example, the master
  119.         side writer "mw" is paired with the slave side reader "r":
  120.  
  121.             mw   -> r
  122.             mr  <-    w
  123.             mrw <-> rw
  124.  
  125.         When operating a pipe where you have a writer into the fifo
  126.         and then a reader from the same fifo, one of the two must
  127.         be a MASTER, with the 'm' flag specified, and the other side
  128.         must be a SLAVE, with the 'm' flag NOT specified, as per
  129.         the example in section (2).
  130.  
  131.     t   tee read.  Usually specified "rt" or "mrt" depending on what
  132.         you want to monitor.  This option causes the read stream to
  133.         be a copy of available read data such that it does NOT
  134.         interfere with other readers.
  135.  
  136.         Otherwise this fifo will compete with other fifos for read
  137.         data.  For a remote shell, tee operation is not desireable
  138.         as a default but is useful to monitor the shell from an
  139.         independent program.
  140.  
  141.         see the REMCLI example below.
  142.  
  143.     s   SHELL mode, creates a separate message port for the handle,
  144.         allowing the shell & programs to find their STDERR handle
  145.         (i.e. the open-* and Console: packets work properly) and
  146.         allowing the use of WaitForChar().
  147.  
  148.         WARNING: use of this option increases overhead in the FIFO:
  149.         device and is generally required to be specified for the slave
  150.         side of a shell (i.e. NewShell fifo:name/rwkecs)
  151.  
  152.         see the REMCLI example below.
  153.  
  154.     C   Send ^C to all (slaves or masters)
  155.     D   Send ^D to all (slaves or masters)
  156.     E   Send ^E to all (slaves or masters)
  157.     F   Send ^F to all (slaves or masters)
  158.  
  159.         You can send one or more signal to all the slaves (or masters
  160.         if 'm' is also included) using these flags.  Note that it is
  161.         not necessary to open a file handle to so, specifying a
  162.         string like this:
  163.  
  164.         "FIFO:fubar/C"
  165.  
  166.         would result in sending a ^C to all fubar slaves even though
  167.         the Open() fails due to the lack of a 'r' or 'w' in the
  168.         specification.
  169.  
  170.              SEE REMCLI.C FOR EXAMPLE IMPLEMENTATION
  171.              OF COOKED MODE AND SIGNALS.
  172.  
  173.  
  174.     (4) TECHNICAL, INTERACTION BETWEEN FIFO: and FIFO.LIBRARY
  175.  
  176.                    LINKED FIFOS
  177.  
  178.     FIFO: provides a full duplex connection using TWO fifo.library FIFOS.
  179.     Opening a fifo in master mode verses slave mode determines which
  180.     names are used for reading and writing.  You should note that when
  181.     a FIFO: handle is opened for both read and write, reading from the
  182.     handle actually accesses a different physical fifo than writing to
  183.     the handle.  Opening a FIFO: for only one direction ('r' *or* 'w')
  184.     results in a half duplex connection.  It is important to properly
  185.     specify the rw modes for the fifo.
  186.  
  187.          FIFO: device             fifo.library
  188.  
  189.     Open("FIFO:junk/w", 1005);              junk_s
  190.     Open("FIFO:junk/r", 1005);              junk_m
  191.     Open("FIFO:junk/rw",1005);              junk_s (w), junk_m (r)
  192.  
  193.     Open("FIFO:junk/wm", 1005);             junk_m
  194.     Open("FIFO:junk/rm", 1005);             junk_s
  195.     Open("FIFO:junk/rwm", 1005);            junk_m (w), junk_s (r)
  196.  
  197.     (5) REMOTE SHELL APPLICATIONS
  198.  
  199.     It is extremely easy to set up a fifo to interface a program with a
  200.     remote shell.  The FIFO: fully supports remote shells including the
  201.     ability to propagate ^C through ^F and handle stderr ("*","CONSOLE:").
  202.  
  203.     Not only that, but programs which need to be able to access the
  204.     master side of a shell in a non-blocking fashion may access the
  205.     master side directly through FIFO.LIBRARY calls.  See FIFOLIB.DOC
  206.     for the function call list, see REMCLI.C for a working example.
  207.  
  208.     1> NewShell FIFO:name/rwkecs
  209.     1> run >nil: RemCLI name
  210.  
  211.     Generally the shell is run off the slave side and the controlling
  212.     program is run off the master side.  The side that runs the shell
  213.     MUST specify the 's' option, as shown above.  Here is a description
  214.     of the flags used in the NewShell line:
  215.  
  216.     rw  full duplex connection.  shell 'reads' from the master and
  217.         'writes' results back to the master.
  218.  
  219.     k   if slave side is started up first, as in the above example, any
  220.         writes it does will NOT be lost.  Not really required since the
  221.         slave side shell does not endcli itself.
  222.  
  223.     e   when slave side closes the handle, an EOF will be sent to
  224.         the master side.
  225.  
  226.     c   run slave side in COOKED mode.  FIFO: will do command line
  227.         editing on any data sent to the slave side.  You do not specify
  228.         COOKED mode for the master side.  I repeat, do NOT specify
  229.         cooked mode for the master side.  (you can't in the above
  230.         example since the master is the 'RemCLI' program.
  231.  
  232.         note that in COOKED mode, FIFO: echoes characters received on
  233.         the slave side back to the master, just like the console
  234.         device.
  235.  
  236.     s   SHELL support, required on the slave specification when run
  237.         from NewShell, causes the handle to get its own message port
  238.         (required to support Open("*", ...) and for WaitForChar() and
  239.         SetMode() to work)
  240.  
  241.     NOTE:  YOU CAN RUN 'RemCLI name' MULTIPLE TIMES SIMULTANIOUSLY
  242.     USING THE SAME FIFO NAME.  All RemCLI's talking to the same shell
  243.     will get all output from the shell and additionally be able to
  244.     issue commands.  This can be extremely useful as a monitoring tool.
  245.  
  246.         1> run >nil: RemCLI name
  247.         1> run >nil: RemCLI name
  248.  
  249.     You can also capture all shell interaction with this:
  250.  
  251.         1> copy FIFO:name/rmt t:capture
  252.  
  253.     The 't' (TEE) specification is required to ensure you do not screw
  254.     up any other readers.  There is no limit on the number of 'readers'
  255.     monitoring a named fifo.  The RemCLI program uses the fifo.library
  256.     to access the master side and thus TEEs automatically.
  257.  
  258.     If RemCLI tries to talk to a fifo that does not exist, it will
  259.     'freeze' until the slave side does exist.  Meaning you can run
  260.     RemCLI before you start up the shell.
  261.  
  262.     CLOSING THE REMCLI WINDOW DOES NOT END THE SHELL.  You must type
  263.     'endcli' or 'endshell' to cause it to exit.  On the other hand,
  264.     closing the RemCLI window and then reopening will yield the
  265.     previous shell (which never exited).
  266.  
  267.  
  268.                 PIPING
  269.  
  270.     You can use the FIFO: device to pipe output from one program to the
  271.     input of another.  Note that you want to be sure to use the 'k' flag
  272.     in case the program generating the output generates only a little (and
  273.     is able to exit before you have a chance to start the reader).  You
  274.     also want to use the 'e' (EOF) option or the reader will not receive
  275.     an EOF, and you must make one side a master.
  276.  
  277.     1> Type s:startup-sequence >FIFO:xx/wkme
  278.     1> Type FIFO:xx/r
  279.  
  280.     Note that Type is inadequate for piping a file because it writes one
  281.     line at a time, increasing overhead. Prefer Copy or cat commands which
  282.     use larger buffers.
  283.  
  284.     If you do not specify the 'e' EOF option then you can run multiple
  285.     programs' output through the pipe sequentially, specifying the EOF
  286.     option only for the last one.
  287.  
  288.     WARNING:    If you ^C the reader before it gets the EOF and exits
  289.     on its own, and if the writer is still writing, the writer will
  290.     freeze up when the fifo becomes full (requiring a reader to unfreeze
  291.     it).  Additionally, if the 'k' option is not used, even if the writer
  292.     does not freeze up there may be unwanted data left in the fifo even
  293.     though nobody is referencing it.
  294.  
  295.     To safely recover from a broken reader, the program controlling the
  296.     pipe must do the following steps:
  297.  
  298.     (1) break the writer if it has not exited (but it may be frozen,
  299.         so...)
  300.  
  301.     (2) open a reader /r and a writer /wme, then immediately close
  302.         the writer.
  303.  
  304.     (3) read from the reader until EOF.  Even if the original writer
  305.         had already exited, the fact that you open and close a dummy
  306.         one will regenerate the EOF.
  307.  
  308.  
  309.     It is currently a bug that EOF is sent continuously to readers, but
  310.     this helps avoiding to freeze or to lock up. A future flag may be added
  311.     to send EOF once only, which is useful in shell applications.
  312.